home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / gs261src.zip / gdevprn.h < prev    next >
C/C++ Source or Header  |  1993-05-20  |  9KB  |  209 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gdevprn.h */
  20. /* Common header file for memory-buffered printers */
  21.  
  22. #include "memory_.h"
  23. #include "string_.h"
  24. #include "gx.h"
  25. #include "gserrors.h"
  26. #include "gsmatrix.h"            /* for gxdevice.h */
  27. #include "gxdevice.h"
  28. #include "gxdevmem.h"
  29. #include "gxclist.h"
  30.  
  31. /* Define the page size parameters. */
  32. /* U.S. letter paper (8.5" x 11"). */
  33. #define DEFAULT_WIDTH_10THS_US_LETTER 85
  34. #define DEFAULT_HEIGHT_10THS_US_LETTER 110
  35. /* A4 paper (210mm x 297mm).  The dimensions are off by a few mm.... */
  36. #define DEFAULT_WIDTH_10THS_A4 83
  37. #define DEFAULT_HEIGHT_10THS_A4 117
  38. /* Choose a default.  A4 may be set in the makefile. */
  39. #ifdef A4
  40. #  define DEFAULT_WIDTH_10THS DEFAULT_WIDTH_10THS_A4
  41. #  define DEFAULT_HEIGHT_10THS DEFAULT_HEIGHT_10THS_A4
  42. #else
  43. #  define DEFAULT_WIDTH_10THS DEFAULT_WIDTH_10THS_US_LETTER
  44. #  define DEFAULT_HEIGHT_10THS DEFAULT_HEIGHT_10THS_US_LETTER
  45. #endif
  46.  
  47. /* Define the parameters for the printer rendering method. */
  48. /* If the entire bitmap fits in PRN_MAX_BITMAP, and there is at least */
  49. /* PRN_MIN_MEMORY_LEFT memory left after allocating it, render in RAM, */
  50. /* otherwise use a command list with a size of PRN_BUFFER_SPACE. */
  51. /* (These are "properties" that can be changed by a Ghostscript program.) */
  52. #if arch_ints_are_short
  53. /* 16-bit machines have little dinky RAMs.... */
  54. #  define PRN_MAX_BITMAP 32000
  55. #  define PRN_BUFFER_SPACE 25000
  56. #  define PRN_MIN_MEMORY_LEFT 32000
  57. #else
  58. /* 32-bit machines have great big hulking RAMs.... */
  59. #  define PRN_MAX_BITMAP 10000000L
  60. #  define PRN_BUFFER_SPACE 1000000L
  61. #  define PRN_MIN_MEMORY_LEFT 500000L
  62. #endif
  63. #define PRN_MIN_BUFFER_SPACE 10000    /* give up if less than this */
  64.  
  65. /* Define the declaration macro for print_page procedures. */
  66. #define dev_proc_print_page(proc)\
  67.   int proc(P2(gx_device_printer *, FILE *))
  68.  
  69. /* Structure for generic printer devices. */
  70. /* This must be preceded by gx_device_common. */
  71. /* Printer devices are actually a union of a memory device */
  72. /* and a clist device, plus some additional state. */
  73. #define prn_fname_sizeof 80
  74. #define gx_prn_device_common\
  75.     byte skip[max(sizeof(gx_device_memory), sizeof(gx_device_clist)) -\
  76.           sizeof(gx_device) + sizeof(double) /* padding */];\
  77.     /* The following is required only for devices where */\
  78.     /* output_page is gdev_prn_output_page; */\
  79.     /* it is ignored for other devices. */\
  80.     dev_proc_print_page((*print_page));\
  81.         /* ------ The following items must be set before ------ */\
  82.         /* ------ calling the device open routine. ------ */\
  83.     long max_bitmap;        /* max size of non-buffered bitmap */\
  84.     long use_buffer_space;        /* space to use for buffer */\
  85.     char fname[prn_fname_sizeof];    /* output file name */\
  86.         /* ------ End of preset items ------ */\
  87.     int file_is_new;    /* boolean, true iff file just opened */\
  88.     FILE *file;            /* output file */\
  89.     char ccfname[60];        /* clist file name */\
  90.     FILE *ccfile;            /* command list scratch file */\
  91.     char cbfname[60];        /* clist block file name */\
  92.     FILE *cbfile;            /* command list block scratch file */\
  93.     long buffer_space;    /* amount of space for clist buffer, */\
  94.                     /* 0 means not using clist */\
  95.     byte *buf;            /* buffer for rendering */\
  96.     int page_count;            /* # of pages printed so far */\
  97.     gx_device_procs *orig_procs;    /* original procs */\
  98.     gx_device_procs mod_procs    /* modified procs */
  99.  
  100. /* The device descriptor */
  101. typedef struct gx_device_printer_s gx_device_printer;
  102. struct gx_device_printer_s {
  103.     gx_device_common;
  104.     gx_prn_device_common;
  105. };
  106.  
  107. /* Macro for casting gx_device argument */
  108. #define prn_dev ((gx_device_printer *)dev)
  109.  
  110. /* Standard device procedures for printers */
  111. dev_proc_open_device(gdev_prn_open);
  112. dev_proc_output_page(gdev_prn_output_page);
  113. dev_proc_close_device(gdev_prn_close);
  114. dev_proc_map_rgb_color(gdev_prn_map_rgb_color);
  115. dev_proc_map_color_rgb(gdev_prn_map_color_rgb);
  116. dev_proc_get_props(gdev_prn_get_props);
  117. dev_proc_put_props(gdev_prn_put_props);
  118.  
  119. /* Macro for generating procedure table */
  120. #define prn_procs(p_open, p_output_page, p_close)\
  121.   prn_matrix_procs(p_open, gx_default_get_initial_matrix, p_output_page, p_close)
  122. #define prn_matrix_procs(p_open,p_get_initial_matrix, p_output_page, p_close)\
  123.  prn_color_matrix_procs(p_open, p_get_initial_matrix, p_output_page, p_close,\
  124.              gdev_prn_map_rgb_color, gdev_prn_map_color_rgb)
  125. /* See gdev_prn_open for explanation of the NULLs below. */
  126. #define prn_color_procs(p_open, p_output_page, p_close, p_map_rgb_color, p_map_color_rgb)\
  127.   prn_color_matrix_procs(p_open, gx_default_get_initial_matrix, p_output_page, p_close, p_map_rgb_color, p_map_color_rgb)
  128. #define prn_color_matrix_procs(p_open, p_get_initial_matrix, p_output_page, p_close, p_map_rgb_color, p_map_color_rgb) {\
  129.     p_open,\
  130.     p_get_initial_matrix,\
  131.     NULL,    /* sync_output */\
  132.     p_output_page,\
  133.     p_close,\
  134.     p_map_rgb_color,\
  135.     p_map_color_rgb,\
  136.     NULL,    /* fill_rectangle */\
  137.     NULL,    /* tile_rectangle */\
  138.     NULL,    /* copy_mono */\
  139.     NULL,    /* copy_color */\
  140.     NULL,    /* draw_line */\
  141.     NULL,    /* get_bits */\
  142.     gdev_prn_get_props,\
  143.     gdev_prn_put_props\
  144. }
  145.  
  146. /* The standard printer device procedures */
  147. /* (using gdev_prn_open/output_page/close). */
  148. extern gx_device_procs prn_std_procs;
  149.  
  150. /* Macro for generating the device descriptor. */
  151. /*
  152.  * The computations of page width and height in pixels should really be
  153.  *    ((int)(page_width_inches*x_dpi))
  154.  * but some compilers (the Ultrix 3.X pcc compiler and the HPUX compiler)
  155.  * can't cast a computed float to an int.  That's why we specify
  156.  * the page width and height in inches/10 instead of inches.
  157.  *
  158.  * Note that the macro is broken up so as to be usable for devices that
  159.  * add further initialized state to the printer device.
  160.  */
  161. #define prn_device_body(devtype, procs, dev_name, width_10ths, height_10ths, x_dpi, y_dpi, l_margin, b_margin, r_margin, t_margin, num_comp, depth, max_gray, max_rgb, dither_gray, dither_rgb, print_page)\
  162.     sizeof(devtype),\
  163.     &procs,\
  164.     dev_name,\
  165.     (int)((long)width_10ths * x_dpi / 10),    /* width */\
  166.     (int)((long)height_10ths * y_dpi / 10),    /* height */\
  167.     x_dpi,\
  168.     y_dpi,\
  169.     l_margin, b_margin, r_margin, t_margin,\
  170.      { num_comp, depth, max_gray, max_rgb, dither_gray, dither_rgb },\
  171.     0,        /* not initialized yet */\
  172.       { 0 },    /* skip */\
  173.     print_page,\
  174.     PRN_MAX_BITMAP,\
  175.     PRN_BUFFER_SPACE,\
  176.       { 0 },    /* fname */\
  177.     0, 0, { 0 }, 0, { 0 }, 0, 0, 0, 0, 0, { 0 }    /* ... mod_procs */
  178. #define prn_device_std_body(devtype, procs, dev_name, width_10ths, height_10ths, x_dpi, y_dpi, l_margin, b_margin, r_margin, t_margin, color_bits, print_page)\
  179.   prn_device_body(devtype, procs, dev_name,\
  180.     width_10ths, height_10ths, x_dpi, y_dpi,\
  181.     l_margin, b_margin, r_margin, t_margin,\
  182.     (color_bits > 1 ? 3 : 1),\
  183.     ((color_bits > 1) & (color_bits < 8) ? 8 : color_bits),\
  184.     (color_bits >= 8 ? 255 : 1),\
  185.     (color_bits >= 8 ? 255 : color_bits > 1 ? 1 : 0),\
  186.     (color_bits >= 8 ? 5 : 2),\
  187.     (color_bits >= 8 ? 5 : color_bits > 1 ? 2 : 0),\
  188.     print_page)
  189. #define prn_device(procs, dev_name, width_10ths, height_10ths, x_dpi, y_dpi, l_margin, b_margin, r_margin, t_margin, color_bits, print_page)\
  190. { prn_device_std_body(gx_device_printer, procs, dev_name,\
  191.     width_10ths, height_10ths, x_dpi, y_dpi,\
  192.     l_margin, b_margin, r_margin, t_margin,\
  193.     color_bits, print_page)\
  194. }
  195.  
  196. /* Common procedures defined in gdevprn.c */
  197. int gdev_prn_open_printer(P2(gx_device *dev, int binary_mode));
  198. #define gdev_prn_file_is_new(pdev) ((pdev)->file_is_new)
  199. #define gdev_prn_raster(pdev) gx_device_raster((gx_device *)(pdev), 0)
  200. int gdev_prn_get_bits(P4(gx_device_printer *, int, byte *, byte **));
  201. int gdev_prn_copy_scan_lines(P4(gx_device_printer *, int, byte *, uint));
  202. int gdev_prn_close_printer(P1(gx_device *));
  203.  
  204. /* BACKWARD COMPATIBILITY */
  205. #define gdev_mem_bytes_per_scan_line(dev)\
  206.   gdev_prn_raster((gx_device_printer *)(dev))
  207. #define gdev_prn_transpose_8x8(inp,ils,outp,ols)\
  208.   memflip8x8(inp,ils,outp,ols)
  209.